Skip to content

JdbcAggregateOperations delete by query #2084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ghgh415263
Copy link
Contributor

Issue link: #1978

Add deleteAllByQuery method to JdbcAggregateOperations

This method enables deleting aggregates based on a query by performing the following steps:

  1. Select root IDs matching the query with a SELECT ... FOR UPDATE to lock the rows.
  2. Delete all sub-entities associated with the selected root IDs.
  3. Delete the root entities identified by the selected IDs.

see
#1978

Issue link: spring-projects#1978

Add deleteAllByQuery method to JdbcAggregateOperations

This method enables deleting aggregates based on a query by performing the following steps:
1. Select root IDs matching the query with a SELECT ... FOR UPDATE to lock the rows.
2. Delete all sub-entities associated with the selected root IDs.
3. Delete the root entities identified by the selected IDs.

Signed-off-by: JaeYeon Kim <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 12, 2025
@ghgh415263
Copy link
Contributor Author

I’ve opened a draft PR for #1978. If you have any suggestions for improvement or spot any issues, I’d be glad to make the necessary changes. Thank you for reviewing it!

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 14, 2025
Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this looks pretty good.
I have on major concern though: We should not transfer the ids from the locking select to the client and use it for follow up deletes.

Instead the locking select should execute on the server only, and the delete operations should be based on the query directly.

The reason for this that this operation is very attractive for large amounts of data. In such cases transporting and converting the ids creates serious load on network and memory.

And if someone prefers to select the ids first and then delete based on these ids they can still do that using multiple methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants